#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
#   GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
#   Author :  Shawn.Tan
#   Date : 2025.10.28
#
#   History : Initial Version 2025.10.28
#
#
from base.exception_handlers.ExceptionsFactory import ExceptionsFactory
from gpgpu.AssemblyHelperGPGPU import AssemblyHelperGPGPU
from gpgpu.exception_handlers.ExceptionHandlerStack import (
    ExceptionHandlerStackGPGPU,
)
from gpgpu.exception_handlers.FastSyncDispatcher import (
    DefaultFastSyncDispatcher,
)
from gpgpu.exception_handlers.PrivilegeLevelHandlerSetGPGPU import (
    PrivilegeLevelHandlerSetGPGPU,
)
from gpgpu.exception_handlers.SyncDispatcher import DefaultSyncDispatcher
from gpgpu.exception_handlers.ThreadHandlerSetGPGPU import (
    ThreadHandlerSetGPGPU,
)


# This class provides an interface for creating various objects necessary
# for the generation of exception handlers for the GPGPU architecture.
class ExceptionsFactoryGPGPU(ExceptionsFactory):

    # Create a set of exception handlers for a given thread.
    #
    #  @param aGenThread A reference to the GenThread object.
    #  @param aMemBankHandlerRegistryRepo A reference to the memory bank
    #       handler registry repository.
    #  @param aStack The exception handler stack.
    def createThreadHandlerSet(self, aGenThread, aMemBankHandlerRegistryRepo, aStack):
        return ThreadHandlerSetGPGPU(aGenThread, aMemBankHandlerRegistryRepo, self, aStack)

    # Create a set of exception handlers for a given privilege level.
    #
    #  @param aGenThread A reference to the GenThread object.
    #  @param aPrivLevel The excecution privilege level.
    #  @param aMemBankHandlerRegistryRepo A reference to the memory bank
    #       handler registry repository.
    #  @param aStack The exception handler stack.
    def createPrivilegeLevelHandlerSet(
        self, aGenThread, aPrivLevel, aMemBankHandlerRegistryRepo, aStack
    ):
        return PrivilegeLevelHandlerSetGPGPU(
            aGenThread, aPrivLevel, aMemBankHandlerRegistryRepo, self, aStack
        )

    # Create an exception handler stack.
    #
    #  @param aGenThread A reference to the GenThread object.
    def createExceptionHandlerStack(self, aGenThread):
        return ExceptionHandlerStackGPGPU(aGenThread)

    # Create a default synchronous exception dispatcher.
    #
    #  @param aGenThread A reference to the GenThread object.
    def createDefaultSynchronousExceptionDispatcher(self, aGenThread):
        return DefaultSyncDispatcher(aGenThread, self)

    # Create a default fast synchronous exception dispatcher.
    #
    #  @param aGenThread A reference to the GenThread object.
    def createDefaultFastSynchronousExceptionDispatcher(self, aGenThread):
        return DefaultFastSyncDispatcher(aGenThread, self)

    # Create an assembly helper object.
    #
    #  @param aSequence A reference to the sequence being generated.
    def createAssemblyHelper(self, aSequence):
        return AssemblyHelperGPGPU(aSequence)
